﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using LHS.Win.Report;
using MS.Core.Constants.Objects;
using LHS.Core.TableInfo;

namespace LHS.Win
{
    public partial class frmSickList : Form
    {
        LHS.Core.Clinical.ClinicalController objController = new LHS.Core.Clinical.ClinicalController();
        // Methods
        public frmSickList()
        {
            this.InitializeComponent();
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btXem_Click(object sender, EventArgs e)
        {
            DataSet dataSet = new DataSet();
         
            if (this.raPYT.Checked)
            {
                List<ExpressionObject> param = new List<ExpressionObject>();
                param.Add(new ExpressionObject("DateExportImport", " between '" + this.ddlNgayA.Value.ToString("MM/dd/yyyy") + " 00:00:00 AM' and dateAdd(dd,1,'" + this.ddlNgayB.Value.ToString("MM/dd/yyyy") + " 00:00:00 AM')", ExpressionObject.eSelectOperator.None));
               DataTable dtMedicineReport= objController.GetData("vw_MedicineReport", param);
            
                if (dtMedicineReport == null || dtMedicineReport.Rows.Count == 0)
                {
                    this.report.Visible = false;
                  
                    MessageBox.Show("Chưa có dữ liệu để thống kê!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                for (int i = 0; i < dtMedicineReport.Rows.Count; i++)
                {
                    string str2 = dtMedicineReport.Rows[i][InfoMedicineImport.MIMPRODUCTIONPERUNIT].ToString();
                    if (str2 == "0")
                    {
                        dtMedicineReport.Rows[i][InfoMedicineImport.MIMID] = "viên";
                    }
                    else if (str2 == "1")
                    {
                        dtMedicineReport.Rows[i][InfoMedicineImport.MIMID] = "ống";
                    }
                    else if (str2 == "2")
                    {
                        dtMedicineReport.Rows[i][InfoMedicineImport.MIMID] = "chai";
                    }
                    else if (str2 == "3")
                    {
                        dtMedicineReport.Rows[i][InfoMedicineImport.MIMID] = "gói";
                    }
                    else
                    {
                        dtMedicineReport.Rows[i][InfoMedicineImport.MIMID] = "tuýp";
                    }
                }
                this.report.Visible = true;
                DataSet ds = new DataSet();
                ds.Tables.Add(dtMedicineReport);
                SickList list = new SickList();
                list.SetDataSource(ds);
                this.report.ReportSource = list ;
            }
            else
            {
                List<ExpressionObject> param = new List<ExpressionObject>();
                param.Add(new ExpressionObject(InfoMedicineExport.MEXDATEEXPORT, " between '" + this.ddlNgayA.Value.ToString("MM/dd/yyyy") + " 00:00:00 AM' and dateAdd(dd,1,'" + this.ddlNgayB.Value.ToString("MM/dd/yyyy") + " 00:00:00 AM')", ExpressionObject.eSelectOperator.None));
                DataTable dtMedicineOrderSource = objController.GetData("vw_MedicineOrderSource", param);

                if (dtMedicineOrderSource == null|| dtMedicineOrderSource.Rows.Count == 0)
                {
                    this.report.Visible = false;
                 
                    MessageBox.Show("Chưa có bác sĩ nào phát thuốc ngoài danh sách!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                for (int j = 0; j < dtMedicineOrderSource.Rows.Count; j++)
                {
                    string str3 = dtMedicineOrderSource.Rows[j][InfoMedicineExport.MEXPRODUCTIONPERUNIT].ToString();
                    if (str3 == "0")
                    {
                        dtMedicineOrderSource.Rows[j][InfoMedicineExport.MEXUSAGEPERDAY] = "viên";
                    }
                    else if (str3 == "1")
                    {
                        dtMedicineOrderSource.Rows[j][InfoMedicineExport.MEXUSAGEPERDAY] = "ống";
                    }
                    else if (str3 == "2")
                    {
                        dtMedicineOrderSource.Rows[j][InfoMedicineExport.MEXUSAGEPERDAY] = "chai";
                    }
                    else
                    {
                        dtMedicineOrderSource.Rows[j][InfoMedicineExport.MEXUSAGEPERDAY] = "gói";
                    }
                }
                this.report.Visible = true;
                DataSet ds = new DataSet();
                ds.Tables.Add(dtMedicineOrderSource);
                MedicineBesidesList list2 = new MedicineBesidesList();
                list2.SetDataSource(ds);
                this.report.ReportSource = list2;
            }
        }

        private void raOther_CheckedChanged(object sender, EventArgs e)
        {
            if (this.raOther.Checked)
            {
                this.raPYT.Checked = false;
            }
            else
            {
                this.raPYT.Checked = true;
            }
        }

        private void raPYT_CheckedChanged(object sender, EventArgs e)
        {
            if (this.raPYT.Checked)
            {
                this.raOther.Checked = false;
            }
            else
            {
                this.raOther.Checked = true;
            }
        }

    }
}